package cn.wolfcode.education.service.impl;

import cn.wolfcode.education.domain.ClientTest;
import cn.wolfcode.education.domain.Employee;
import cn.wolfcode.education.mapper.ClientTestMapper;
import cn.wolfcode.education.query.QueryObject;
import cn.wolfcode.education.service.IClientTestService;
import cn.wolfcode.education.util.PageResult;
import org.apache.shiro.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class ClientTestServiceImpl implements IClientTestService {
    @Autowired
    private ClientTestMapper clientTestMapper;

    public PageResult queryForList(QueryObject qo) {
        int count = clientTestMapper.queryForCount(qo);
        if (count == 0){
            return new PageResult();
        }
        return new PageResult(count,clientTestMapper.queryForList(qo));
    }

    public void insertTest(ClientTest clientTest) {
        //设置考试状态未未考试
        clientTest.setTestState(ClientTest.STATIC_NOTEST);
        clientTestMapper.insertTest(clientTest);
    }

    public void savegrade(ClientTest clientTest) {
        //需要设置当前用户
        /*Employee employee = new Employee();
        clientTest.setHandler(employee);*/
        Employee currentUser = (Employee) SecurityUtils.getSubject().getPrincipal();
        clientTest.setHandler(currentUser);
        clientTestMapper.updategrade(clientTest);
    }

    public void delete(Long id) {
        clientTestMapper.deleteByPrimaryKey(id);
    }
}
